package com.rlz.framemm.mode.observer

import com.rlz.base.design.observer.Observable
import com.rlz.base.design.observer.Observer

/**
 * Created by RLZ
 * on 2021/10/25
 *
 */
class DingServer<T> : Observable<T> {

    private var mList: ArrayList<Observer<T>> = ArrayList()

    private var mData: T? = null

    override fun register(o: Observer<T>) {
        mList.add(o)
    }

    override fun remove(o: Observer<T>) {
        if (mList.contains(o)) {
            mList.remove(o)
        }
    }

    override fun notice() {
        mList.forEach {
            it.update(mData!!)
        }
    }

    fun issue(data: T) {
        mData = data
        println("服务器发布消息 $data")
        notice()
    }
}